//
//  ViewController.m
//  28-UIViewAnimation(2)
//
//  Created by 曹曹 on 16/8/22.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "ViewController.h"
#import "UIView+Frame.h"

@interface ViewController ()
@property (nonatomic, strong) UIView *animationView;
@property (nonatomic, strong) UIButton *animationButton;
@property (nonatomic, strong) UIButton *fromButton;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    UIViewAnimationOptionLayoutSubviews//进行动画时布局子控件
//    UIViewAnimationOptionAllowUserInteraction//进行动画时允许用户交互
//    UIViewAnimationOptionBeginFromCurrentState//从当前状态开始动画
//    UIViewAnimationOptionRepeat//无限重复执行动画
//    UIViewAnimationOptionAutoreverse//执行动画回路
//    UIViewAnimationOptionOverrideInheritedDuration//忽略嵌套动画的执行时间设置
//    UIViewAnimationOptionOverrideInheritedCurve//忽略嵌套动画的曲线设置
//    UIViewAnimationOptionAllowAnimatedContent//转场：进行动画时重绘视图
//    UIViewAnimationOptionShowHideTransitionViews//转场：移除（添加和移除图层的）动画效果
//    UIViewAnimationOptionOverrideInheritedOptions//不继承父动画设置
//    UIViewAnimationOptionCurveEaseInOut//时间曲线，慢进慢出（默认值）
//    UIViewAnimationOptionCurveEaseIn//时间曲线，慢进
//    UIViewAnimationOptionCurveEaseOut//时间曲线，慢出
//    UIViewAnimationOptionCurveLinear//时间曲线，匀速
//    UIViewAnimationOptionTransitionNone//转场，不使用动画
//    UIViewAnimationOptionTransitionFlipFromLeft//转场，从左向右旋转翻页
//    UIViewAnimationOptionTransitionFlipFromRight//转场，从右向左旋转翻页
//    UIViewAnimationOptionTransitionCurlUp//转场，下往上卷曲翻页
//    UIViewAnimationOptionTransitionCurlDown//转场，从上往下卷曲翻页
//    UIViewAnimationOptionTransitionCrossDissolve//转场，交叉消失和出现
//    UIViewAnimationOptionTransitionFlipFromTop//转场，从上向下旋转翻页
//    UIViewAnimationOptionTransitionFlipFromBottom//转场，从下向上旋转翻页
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.animationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];;
    _animationView.backgroundColor = [UIColor redColor];
    [self.view addSubview:_animationView];
    // 参数3: 阻尼系数 0.0 ~ 1.0 数值越小, 阻力越小, 数值越大, 阻力越大
    // 参数4: 速度
    // 参数5: 选项
    [UIView animateWithDuration:5 delay:0 usingSpringWithDamping:1.0f initialSpringVelocity:0.0f options:UIViewAnimationOptionCurveLinear animations:^{
        _animationView.gx_width = 100;
        _animationView.gx_height = 300;
        _animationView.backgroundColor = [UIColor greenColor];
    } completion:^(BOOL finished) {
        
    }];
    self.animationButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _animationButton.frame = CGRectMake(100, 100, 200, 100);
    _animationButton.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:_animationButton];
    [_animationButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    self.fromButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _fromButton.frame = CGRectMake(200, 200, 200, 100);
    _fromButton.backgroundColor = [UIColor orangeColor];
    
    [_fromButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)buttonClicked:(UIButton *)button {
    // 参数1: 需要执行动画的View
    // 参数2: 持续时间
    // 参数3:
//    [UIView transitionWithView:_animationButton duration:2 options:UIViewAnimationOptionTransitionFlipFromTop animations:^{
//        _animationButton.gx_height = 200;
//    } completion:^(BOOL finished) {
//        // 动画可以嵌套动画
//        [UIView animateWithDuration:0.5 animations:^{
//            _animationButton.gx_height = 100;
//        }];
//    }];
    // toView added to fromView.superview, fromView removed from its superview
    [UIView transitionFromView:_animationButton toView:_fromButton duration:5 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {
        
        NSLog(@"9999");
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
